home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls085.solintel.Z / tls085.solintel / lib / vtcl / examples / fortune.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  6.0 KB  |  274 lines

  1. #/* CVS $Id: fortune.tcl,v 1.1 1995/02/03 16:24:49 zibi Exp $ */
  2. #!/bin/vtcl
  3. # graphical front end to NET2 Bsd fortune cmd
  4. # Not support percentage distributions or pattern match specifications
  5. # or a lot of switches...
  6. #
  7.  
  8. # NET2 fortune switches :
  9. #   -a all  -l long, -s short, -e - treat files as equal size
  10. #   -i nocase in pattern, -m <pattern> match pattern    
  11. #   -f print file list
  12. #   -f file - use file for fortunes
  13. #   -o offensive 
  14. #   -w wait before exiting 
  15. #
  16.  
  17. # Demoing VTcl for '94 devForum
  18. #   Hops 08.18.94
  19.  
  20.  
  21. # ---------------- setup Globals  ---------------- 
  22.  
  23. set in_FortFile "fortunes" ;# Initial Fortune File ( all )
  24. set FortFile $in_FortFile
  25. set arg ""                          ;# switches passed to fortune binary
  26. set repeatStatus ""                 ;# Timer ID
  27.  
  28. set Fort_bin    "/usr/local/bin/fortune"
  29. set Fortunes_File_List { fortunes    
  30.         fortunes/fortunes     fortunes/startrek    
  31.         fortunes/zippy        fortunes/other-fortunes
  32.         fortunes/fortunes-o
  33.     }
  34.  
  35.  
  36.  
  37. # ---------------- Callback Procs ----------------
  38.  
  39. proc quitCB {cbs} {
  40.     VtClose
  41.     exit 0
  42. }
  43.  
  44.  
  45. # ---- Run the fortune and display the fortune string ----
  46.  
  47. proc fortuneCB { outw cbs } {
  48.     global arg FortFile Fort_bin
  49.  
  50.     catch { eval exec $Fort_bin -e -s $arg $FortFile } a
  51.  
  52.     #puts $a
  53.     puts "./fortune $arg $FortFile "
  54.  
  55.     set arg ""
  56.  
  57.  
  58.     WsSetValues $outw -value $a
  59. }
  60.  
  61.  
  62.  
  63. # ---- Callback that sets the fortune file for the ComboBox ----
  64. proc CBFileItemCB { cbs} {
  65.     global FortFile
  66.  
  67.     set FortFile [ keylget cbs value ]
  68.  
  69. #puts $FortFile
  70.  
  71. }
  72.  
  73.  
  74. # Reset fortune file
  75. proc FileMenuResetCB { cbs } {
  76.     global FortFile in_FortFile cb
  77.  
  78.     set FortFile $in_FortFile
  79.  
  80.     WsSetValues $cb -value $FortFile
  81. }
  82.  
  83.  
  84. #proc destroyDialog {cbs } {
  85. #echo "destroy"
  86. #    WsDestroyDialog [ keylget cbs widget ]
  87. #}
  88.  
  89. proc nyiCB { cbs } {
  90.     global app
  91.  
  92.     VtShowDialog [ VtErrorDialog $app.err       \
  93.         -message "This option is Not Yet Implemented" \
  94.         -ok                                 \
  95.         -okLabel "Dismiss"                  \
  96.         ]
  97. #        -okCallback destroyDialog          \
  98. #        -autoDestroy False                 \
  99. #        -autoHide False                    \
  100.  
  101. }
  102.  
  103.  
  104. # ---- Repeat timer handling ----
  105.  
  106. # display fortune and restore timer for next iteration
  107. proc TOfortuneCB { cbs } {
  108.     global repeatStatus text
  109.  
  110.     fortuneCB $text $cbs
  111.  
  112.     set repeatStatus [ WsAddTimeOut     \
  113.             -callback { TOfortuneCB }   \
  114.             -interval 2000              \
  115.             ]
  116. # puts $repeatStatus
  117. }
  118.  
  119. # setup initial call to make fortune repeat
  120. proc RepeatCB { cbs } {
  121.     global repeatStatus
  122.  
  123.     if { $repeatStatus != "" } {
  124.         WsRemoveTimeOut $repeatStatus
  125.         set repeatStatus ""
  126.     }   \
  127.     else \
  128.     {
  129.         set repeatStatus [ WsAddTimeOut \
  130.             -callback { TOfortuneCB }   \
  131.             -interval 100               \
  132.             ]
  133.     }
  134.  
  135. }
  136.  
  137. # ---------------- Widget Hier Setup procs ----------------
  138.  
  139. # -- MenuBar --
  140. proc genericCB {cbs } {}
  141.  
  142. proc mkMenuBar { parent } {
  143.  
  144. # pulldown : pd name mnemonic accel
  145. # button   : bt name mnemonic accel  accelString Callback 
  146. # separator: sp
  147.  
  148. set menuList {
  149.     {pd File P}
  150.         {bt Reset   R "" "" FileMenuResetCB    }
  151.         {sp}
  152.         {bt Exit    E "" "" quitCB   }
  153.   
  154.     {pd View V}
  155.         {bt LargeFont    A "" "" nyiCB    }
  156.         {bt SmallFont    F "" "" nyiCB    }
  157. }
  158.  
  159.  
  160.     set menubar [VtMenuBar $parent.menubar -helpMenuItemList {INDEX ON_VERSION}]
  161.     VxMenu $parent $menubar $menuList genericCB
  162.  
  163.     return $menubar         
  164. }
  165.  
  166.  
  167. # -- Config items frame and buttons --
  168. proc mkConfigBtns { parent { Top "FORM" } { Left "FORM"} {Right "FORM"} } {
  169.  
  170.     set frame [ VtFrame $parent.frame   \
  171.         -title      "Config"            \
  172.         -shadowType ETCHED_IN           \
  173.         -topSide    $Top                \
  174.         -leftSide   $Left               \
  175.         -rightSide  $Right              \
  176.         ]
  177.  
  178.     set fform [ VtForm $frame.form  ]
  179.  
  180.     set btn2  [ VtPushButton $fform.b2  \
  181.         -label    Files                 \
  182.         -callback { set arg "-f" ; fortuneCB $text }  \
  183.         ]    
  184.  
  185.     set btn3 [ VtPushButton $fform.b3 \
  186.         -label  Short               \
  187.         -callback { set arg "-s" ; fortuneCB $text }  
  188.         ]    
  189.  
  190.     set btn4  [ VtPushButton $fform.b4 \
  191.         -label Repeat...            \
  192.         -callback { RepeatCB }      \
  193.         ]    
  194.     return $frame
  195. }
  196.  
  197.  
  198. #---- Main program Widget Logic ---- 
  199.  
  200. # mainline 
  201.  
  202. # Open Server connection 
  203. set app [VtOpen Fortune ] 
  204.  
  205. VtSetAppValues $app -versionString "Fortune 1.0\n Hops 08.19.94"
  206.  
  207. # Make popup Form 
  208. set form [ VtFormDialog  $app.form  \
  209.     -title "Fortune"                \
  210.     -wmCloseCallback quitCB         \
  211.     ]
  212.  
  213.  
  214. set mb [ mkMenuBar $form]
  215.  
  216. #set top FORM
  217. set top $mb
  218.  
  219. # Field for Display of fortune string
  220. set text [ VtText $form.text    \
  221.     -readOnly                   \
  222.     -columns 60                 \
  223.     -horizontalScrollBar TRUE   \
  224.     -verticalScrollBar TRUE     \
  225.     -rows 10                    \
  226.     -topSide $top               \
  227.     -leftSide FORM              \
  228.     ]
  229.  
  230. #    -wordWrap 
  231.  
  232.  
  233. # Combobox for selection of fortune file
  234. set lbl [ VtLabel $form.lbl -label "Fortune File" \
  235.     -topSide $text\
  236.     ]
  237.  
  238. # Now Buttons ( RHS ) 
  239. set cb [ VtComboBox $form.combo     \
  240.     -value $FortFile                \
  241.     -itemList $Fortunes_File_List   \
  242.     -valueChangedCallback CBFileItemCB \
  243.     -topSide $lbl                   \
  244.     -bottomSide FORM                \
  245.     ]
  246.  
  247. # Btn for a single fortune
  248. set btn1 [ VtPushButton $form.btn1  \
  249.     -label "Fortune"                \
  250.     -callback { fortuneCB $text }   \
  251.     -leftSide $text                 \
  252.     -topSide $top                   \
  253.     -rightSide FORM                 \
  254.     ]
  255.  
  256. # Config Box
  257. set frame [ mkConfigBtns $form $btn1 $text ]
  258.  
  259.  
  260. # Quit Btn
  261. set btnE  [ VtPushButton $form.bE \
  262.     -label Quit                 \
  263.     -callback { quitCB }        \
  264.     -topSide $frame             \
  265.     -leftSide $text             \
  266.     -rightSide FORM             \
  267.     ]    
  268.  
  269.  
  270.  
  271. # Start everything going 
  272. VtShow $form
  273. VtMainLoop
  274.